from typing import Optional

# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

class Solution:
    def reorderList(self, head: Optional[ListNode]) -> None:
        """
        Do not return anything, modify head in-place instead.
        """
        if head is None:
            return

        nodes = []
        node = head
        while node:
            nodes.append(node)
            node = node.next

        n = len(nodes)
        indices = [x for i, j in zip(range(n), range(n-1, -1, -1)) for x in [i, j]][:n]
        new_nodes = [nodes[i] for i in indices]
        for i in range(n-1):
            new_nodes[i].next = new_nodes[i+1]
        new_nodes[-1].next = None



